package com.gonsin.gmessage.logic.websocket;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

@Data
@ToString
@ApiModel("websocket发送内容")
public class MessageBo {

    @ApiModelProperty("协议头，固定gonsin")
    private String head = "gonsin";

    @ApiModelProperty("指令类型")
    private Cmd cmd = new Cmd();

    @ApiModelProperty("指令参数")
    private Map<String, Object> args = new HashMap<>();

    private MessageBo(){ }

    public static MessageBo create(){
        return new MessageBo();
    }

    public MessageBo cmd(String cmd) {
        this.cmd.cmd = cmd;
        return this;
    }

    public MessageBo subCmd(String subCmd){
        this.cmd.subcmd = subCmd;
        return this;
    }

    public MessageBo response(int response){
        this.cmd.response = response;
        return this;
    }

    /**
     * 添加参数
     */
    public MessageBo addArgs(String key, Object value){
        args.put(key, value);
        return this;
    }

    /**
     * 添加参数
     */
    public MessageBo args(Map<String, Object> args){
        this.args = args;
        return this;
    }

    @Data
    @ApiModel("指令类型")
    public class Cmd {

        @ApiModelProperty("主指令")
        private String cmd;

        @ApiModelProperty("次级指令")
        private String subcmd;

        @ApiModelProperty("保留，暂时没用")
        private int response = 0;
    }
}
